Repository navigation
fix(android): read CapacitorCookies/CapacitorHttp isEnabled from injected global - #8745
Open
basnijholt wants to merge 2 commits into
Open
basnijholt wants to merge 2 commits into
basnijholt wants to merge 2 commits into
Conversation
…cted global Assisted-by: MindRoom DevAgent:google/gemini-4-neon <https://github.com/mindroom-ai/mindroom>
4 of 8 tasks
…nfig-js-interfaces
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Extend the
window.CapacitorNativeConfigmechanism (added for iOS in #8688, #8689 onnext) to Android soCapacitorHttpandCapacitorCookiesdo not unconditionally registeraddJavascriptInterfaceobjects just to reportisEnabled():JSExport.getGlobalJS(context, loggingEnabled, isDebug, cookiesEnabled, httpEnabled)overload emittingwindow.CapacitorNativeConfig = { cookiesEnabled, httpEnabled };(leaving the 3-argument overload unchanged so custom callers keep using the fallback), and pass plugin flags fromBridge.getJSInjector().core/native-bridge.ts(and regenerate bothandroid/andios/native-bridge.js) to readwindow.CapacitorNativeConfigfirst on Android, fall back toCapacitorHttpAndroidInterface.isEnabled()/CapacitorCookiesAndroidInterface.isEnabled()when absent, and avoid patchingdocument.cookieon Android ifCapacitorCookiesAndroidInterfaceis absent.addJavascriptInterfacein bothCapacitorHttp.load()andCapacitorCookies.load()behindif (isEnabled())so apps that do not enable either plugin do not expose frame-unaware@JavascriptInterfaceobjects.ARCHITECTURE.mdto reflect the config-first check and gated fallback interfaces.Change Type
Rationale / Problems Fixed
WebView.addJavascriptInterfaceexposes methods to every frame in the WebView without frame or origin identification. Previously bothCapacitorHttpAndroidInterfaceandCapacitorCookiesAndroidInterfacewere registered unconditionally even when both plugins were disabled. Reading the staticenabledflags fromwindow.CapacitorNativeConfigmatches iOS (#8688) and registers neither interface unless its plugin is enabled.No related issue. Happy to move this to a discussion first if you prefer.
Tests or Reproductions
Added tests:
core/src/tests/bridge.spec.ts: AndroidCapacitorNativeConfig.httpEnabled(truewithout interface,falsetaking precedence over interface) and browserdocument.cookieround-trip whenCapacitorCookiesAndroidInterfaceis absent.android/capacitor/src/test/java/com/getcapacitor/JSExportTest.javaandroid/capacitor/src/test/java/com/getcapacitor/plugin/CapacitorHttpTest.javaandroid/capacitor/src/test/java/com/getcapacitor/plugin/CapacitorCookiesTest.javaRan locally:
npm run build:nativebridge— passed (regenerated bothnative-bridge.jscopies)npm run build -w core— passednpm test -w core— passed (6 suites, 59 tests)npm run eslint— passednpm run prettier -- --check— passedNot run locally:
npm run verify -w android): no JDK 21 / Android SDK here, left to CI.npm run verify -w ios/ SwiftLint: macOS only; no Swift sources changed (only the regenerated iOSnative-bridge.js).Screenshots / Media
N/A
Platforms Affected
native-bridge.jsonly; behaviour unchanged)Notes / Comments
native-bridge.jscopies include 3 pre-existing drift hunks from chore: update eslint to v10 and @ionic/eslint-config to v0.5.0 #8596 (rebuilding untouchedmaingives the same 3 hunks); iOS runtime behavior is unchanged.CapacitorCookies.load()and addCapacitorCookiesTest.java; if both land, combine the guard asisEnabled() && !bridge.hasScopedWebMessages()and merge the test cases.window.CapacitorCookiesAndroidInterface/window.CapacitorHttpAndroidInterfaceglobals are now absent when their plugin is disabled; readwindow.CapacitorNativeConfiginstead (as on iOS since fix(ios): read CapacitorCookies/CapacitorHttp isEnabled from injected global #8688).next.google/gemini-4-neon); the commands under Tests were run.